﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace SocketClient
{
   public class TcpSocketRequest
    {
        public int SocketConnectServer()
        {
            return SocketClient.ConnectServer();
        }

        public int SendData(string message)
        {
            if(!SocketClient.isConnected)
                SocketClient.ConnectServer();
            //SocketClient.SendToServer(message);
            try
            {
                NetworkStream clientStream = SocketClient.client.GetStream();
                UTF8Encoding encoder = new UTF8Encoding();
                byte[] buffer = encoder.GetBytes(message);
                clientStream.Write(buffer, 0, buffer.Length);
                clientStream.Flush();
                return 1;
            }
            catch (Exception)
            {
                SocketClient.isConnected = false;
                SocketClient.client.Close();
                return 0;
            }
        }
    }
}
